<template>
<view>
<view v-for="(item, index) in getList" :key="index" class="content">
   <image :src="item.avatar"></image>
   <view class="con">
      <view>{{item.nickname}}</view>
      <view>{{item.add_time}}</view>
      <view>资金：
         <span>￥{{item.money}}</span>
      </view>
      <view>邀请码：
         <span>{{item.id}}</span>
      </view>
   </view>
   <view class="num">{{index+1}}</view>
</view>
<view v-if="noshop" class="noshop">没有更多了...</view>
</view>
</template>

<script>
// hotmall/packageB/Rich/Rich.js
var app = getApp();
import api from "../../../api";

export default {
  data() {
    return {
      page: 1,
      uid: '',
      getList: [],
      noshop: false
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //   wx.showLoading({
    //      title: '加载中',
    //   })
    //    wx.getStorage({
    //       key: 'userId',
    //       success: (res) => {
    //          console.log(res)
    //          this.setData({
    //             uid: res.data
    //          })
    //          this.getList()
    //       },
    //    });
    this.getListFun();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getListFun();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      page: this.page + 1
    });
    this.getListFun();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    getListFun: function () {
      app.globalData.request({
        url: api.default.distribution_lower,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          page: this.page
        },
        method: 'POST',
        success: res => {
          console.log(res);
          var list = res.data;

          for (var i = 0; i < list.length; i++) {
            list[i].money = Number(list[i].money).toFixed(2);
          } // console.log(list)


          wx.hideLoading();

          if (this.page == 1) {
            this.setData({
              getList: list
            });
          } else {
            if (res.data.length == 0) {
              this.setData({
                noshop: true
              });
            } else {
              var shop = this.getList;

              for (let i = 0; i < res.data.length; i++) {
                shop.push(shop[i]);
              }

              this.setData({
                getList: shop
              });
              console.log(this.shopList);
            }
          }

          if (this.getList.length == 0) {
            this.setData({
              noshop: true
            });
          }
        }
      });
    }
  }
};
</script>
<style>
@import "./Rich.css";
</style>